package useTask.hbaseTask;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;

public class insertHbase {
    static Configuration conf;
    static Connection HConn;
    static Table table;

    public static void insert(String tableName,String rowkey,String family,String column,String value) throws IOException {
        conf = HBaseConfiguration.create();
        HConn = ConnectionFactory.createConnection(conf);
        table = HConn.getTable(TableName.valueOf(tableName));

        Put put = new Put(rowkey.getBytes()); // put “表名”，“行建”
//        put.addColumn(列柱，列名，值)
        put.addColumn(family.getBytes(),column.getBytes(),value.getBytes());
        // 提交数据
        table.put(put);

        System.out.println("数据插入成功！！！");

        // 释放资源
        table.close();
        HConn.close();
    }
}
